import { url_log } from "@/comm/api";
import { get, patch, post, remove } from "@/comm/request";
import { defineStore } from "pinia";
import { format } from "@/comm/format"
import { useVideoStore } from "./video";
const videoStore = useVideoStore();


interface IState {
    list: any[];
}

const defaultStore = {
    list: [] as any[],
    totalPages: 0,
    page: 1,
    limit: 10,
    username: "",
    sort: 0,
}
// const IState = typeof defaultStore

export const useLogStore = defineStore({
    id: "log",
    state: () => defaultStore,
    actions: {
        async addLog(param: any) {
            post(url_log, param, true);
        },
        async load() {
            const param: any = { page: this.page, limit: this.limit, username: this.username, sort: this.sort };
            if (this.username) {
                param.username = this.username;
            }
            let res: any = await post(url_log + "/all", param, true);
            console.log("res", res)
            this.list = res.data.list;
            // this.list.forEach(i => {
            //     i.formatTimer = format(i.timer);
            //     if (videoStore.well) {
            //         i.formatImg = videoStore.well_poster;
            //     }
            //     else{
            //         i.formatImg =  "https://www.step2step.cn/proxy/images/" + i.pic;
            //     }
                
            // })
            this.totalPages = res.data.pagination.totalPages;
        },
    }
});
